package com.lidong.lowcode.model.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.page.PageMethod;
import com.lidong.config.domain.common.PageParam;
import com.lidong.config.domain.gloabreturn.PageInfoVO;
import com.lidong.config.domain.gloabreturn.ResponseInfo;
import com.lidong.lowcode.model.domain.BaseDataSource;
import com.lidong.lowcode.model.domain.BaseDataSourceExample;
import com.lidong.lowcode.model.mapper.BaseDataSourceMapper;
import com.lidong.lowcode.model.mapper.BaseGroupMapper;
import com.lidong.lowcode.model.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 5/3/2022 5:27 PM
 */
@Service
public class DataSourceServiceImpl implements DataSourceService {

    @Autowired
    private BaseDataSourceMapper datasourceMapper;

    @Autowired
    private BaseGroupMapper groupMapper;

    /**
     * 分页查询
     *
     * @param pageParam pageParam
     * @return PageInfoVO
     */
    @Override
    public PageInfoVO<BaseDataSource> getPageBaseDataSource(PageParam pageParam) {
        PageInfoVO<BaseDataSource> pageInfoVO = new PageInfoVO<>(pageParam);
        PageMethod.startPage(pageParam.getPageNumber(), pageParam.getPageSize());
        if (pageParam.getParmaMap().isEmpty()) {
            List<BaseDataSource> baseDataSources = datasourceMapper.selectByExample(new BaseDataSourceExample());
            pageInfoVO.setData(baseDataSources);
            pageInfoVO.setTotal(baseDataSources.size());
            pageInfoVO.setCode(ResponseInfo.SUCCESS);
        }
        return pageInfoVO;
    }



}
